<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>平台管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">
  		<div class="layui-col-md12">
		    <div class="layui-card">
		      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
		        <div class="layui-form-item">
		          <div class="layui-inline">
		            <label class="layui-form-label">商家ID</label>
		            <div class="layui-input-inline">
		              <input type="text" name="bid" placeholder="请输入" autocomplete="off" class="layui-input">
		            </div>
		          </div>
		          <div class="layui-inline">
		            <label class="layui-form-label">商家账号</label>
		            <div class="layui-input-inline">
		              <input type="text" name="phone" placeholder="请输入" autocomplete="off" class="layui-input">
		            </div>
		          </div>
		          <div class="layui-inline">
		            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
		              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
		            </button>
		          </div>
		        </div>
		      </div>
		
		      <div class="layui-card-body">
		        <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
		        <script type="text/html" id="nickNameTpl">
				{{# if(d.onOff == 0 || d.onOff == 2){ }}
					{{ d.nickNameOn }}
				{{# }else{ }}
					{{ d.nickName}}
				{{# } }}
				</script>
		        <script type="text/html" id="table-operate">
         		<a class="layui-btn layui-btn-xs" lay-event="detail">查看明细</a>
        		</script>
		      </div>
		    </div>   		
  		</div>
  	</div>
  </div>

  <script src="/layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var table = layui.table
    ,form = layui.form;
    
    table.render({
        elem: '#LAY-app-content-list'
        ,url: '/account/queryBusinessAccount'
        ,request:{
        	pageName:'current',
			limitName: 'size' //每页数据量的参数名，默认：limit
        }
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,totalRow:true
        ,cols: [[
          {field:'bid', minWidth:80, title: '商家ID', sort: true,totalRowText:'小计：'}
          ,{field:'money', minWidth:80, title: '当前余额',sort: true,totalRow: true}
          ,{field:'freezeMoney', minWidth:80, title: '当前冻结余额', sort: true,totalRow: true}
          ,{minWidth:80, title: '商家名称',templet:'#nickNameTpl'}
          ,{field:'phone', minWidth:80, title: '商家账号'}
          ,{field:'scopeName', minWidth:80, title: '经营范围'}
          ,{title:'操作',width:178, align:'center', fixed: 'right', toolbar: '#table-operate'}
        ]]
    	,page: true
       	,parseData: function(res){ //res 即为原始返回的数据
   	        return {
   	          "code": res.code, //解析接口状态
   	          "msg": res.msg, //解析提示文本
   	          "count": res.count, //解析数据长度
   	          "data": res.data //解析数据列表
           	};
       	}
     });
    
    
    //监听搜索
    form.on('submit(LAY-app-contlist-search)', function(data){
      var field = data.field;
      
      //执行重载
      table.reload('LAY-app-content-list', {
        where: field
      });
    });
    
    
  	//监听工具条
    table.on('tool(LAY-app-content-list)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
      var data = obj.data; //获得当前行数据
      var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      var tr = obj.tr; //获得当前行 tr 的DOM对象
      if(layEvent === 'detail'){ //查看
    	  window.location.href='/account/businessAccountDetail?bid='+data.bid;  
      } else if(layEvent === 'del'){ //删除
        layer.confirm('真的删除行么', function(index){
          obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
          layer.close(index);
          //向服务端发送删除指令
        });
      } else if(layEvent === 'edit'){ //编辑
        //do something
        
        //同步更新缓存对应的值
        obj.update({
          username: '123'
          ,title: 'xxx'
        });
      }
    });    

  });
  </script>
</body>
</html>
